﻿using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Collections.Generic;

namespace Light
{
    enum LightStatus
    {
        LEFT,               // 红灯
        LEFT_FLASH,         // 红灯闪
        STRAIGHT,           // 直行灯
        STRAIGHT_FLASH,     // 直行灯闪
        YELLOW,             // 黄灯
        YELLOW_FLASH,       // 黄灯闪
        RED,                // 红灯
        OFF                 // 关闭
    }

    partial class TrafficLight : UIElement
    {
        #region 灯属性设置
        int ID;
        int _YellowTime;
        int _RedTime;
        int _LEFT;
        int _STRAIGHT;

        public int YellowTime
        {
            get { return _YellowTime;  }
            set { _YellowTime = value; Update(); }
        }

        public int RedTime
        {
            get { return _RedTime;  }
            set { _RedTime = value; Update(); }
        }

        public int Left
        {
            get { return _LEFT; }
            set { _LEFT = value; Update(); }
        }

        public int Straight
        {
            get { return _STRAIGHT;  }
            set { _STRAIGHT = value; Update(); }
        }

        int Time_Remained;              // 当前状态剩余时间
        public int TimeRemained
        {
            get { return Time_Remained; }
            set { Time_Remained = value; }
        }
        #endregion

        #region 灯状态get/set
        LightStatus _Status;      // 状态
        public LightStatus Status
        {
            get
            {
                return _Status;
            }
            set
            {
                _Status = value;
                Update();
            }
        }
        #endregion

        Road road;

        public TrafficLight( int id, Canvas p, Road r )
        {
            ID = id;
            road = r;
            parentCanvas = p;
            _Status = LightStatus.OFF;

            time.Orientation = Orientation.Horizontal;
            time.HorizontalAlignment = HorizontalAlignment.Left;

            time.Width = 100;
            time.Height = 100;

            Update();
        }

        // 更新自己的状态，在每次设置自己属性时会被调用
        void Update()
        {
            // 更新图形
            UpdateDraw();

            // 状态机

        }

        void OnTimeZero()
        {
            road.OnTimeZero( ID );
        }


        // 每个50ms调用一次
        public override void OnAnimate()
        {
            /// 交通灯的处理函数
        }
    }
}
